<?php
/**
* @version 1.0.0
* @package RSSearch! 1.0.0
* @copyright (C) 2011 www.rsjoomla.com
* @license GPL, http://www.gnu.org/copyleft/gpl.html
*/
defined('_JEXEC') or die('Restricted access');

class JElementContentsections extends JElement{
	var $_name = 'Contentsections';

	function fetchElement($name, $value, &$node, $control_name)
	{
		$result = '<script type="text/javascript">
				window.addEvent(\'domready\',function(){
					if(document.getElementById("sections_btn").checked){
						document.getElementById("listsections").style.visibility="visible";
						document.getElementById("desc_sections").style.visibility="hidden";
					}else {
						document.getElementById("listsections").style.visibility="hidden";
						document.getElementById("desc_sections").style.visibility="visible";
					}
				});
				</script>';
		$result .= '<div id="desc_sections" style="visibility:visible;margin-top: 30px;">'.JText::_('RSF_CONT_XML_SECTIONS_LIST_DESC').'</div>';
		$result .= '<div id="listsections" style="visibility:hidden;">';
			$db =& JFactory::getDBO();
			$query = "SELECT * FROM #__sections ORDER BY `title` ASC";
			$db->setQuery($query);
			$cats = $db->loadObjectList();
			
			$tmp = new stdClass();
			$tmp->id 	= 0;
			$tmp->title = JText::_('Uncategorised');
			array_unshift($cats, $tmp);
			
		$result .= JHTML::_('select.genericlist', $cats, $control_name.'[sections][]', 'multiple="multiple"', 'id', 'title', $value);
		$result .= '</div><div style="clear:both;"></div>';
		
		return $result;
	}
}